package com.learning.cloud.controller;

import com.learning.cloud.entity.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * description:
 *
 * @author minghuiZhang
 * @date created in  15:28 2018/4/28
 * modified by
 */
@RestController
@Slf4j
public class MovieController {
	@Autowired
	private RestTemplate restTemplate;
	@Autowired
	private LoadBalancerClient loadBalancerClient;

	@GetMapping("/movie/{id}")
	@HystrixCommand(fallbackMethod = "findByIdFallback")
	public User findById(@PathVariable("id") Long id){

		return this.restTemplate.getForObject( "http://microservice-provider-user:7900/simple/" + id,User.class);
	}

	private User findByIdFallback(Long id){
		User user = new User();
		user.setId(0L);
		return user;
	}

}
